// ****************************************************************************
// Copyright Swordfish Computing Australia 2006                              **
// http://www.swordfish.com.au/                                              **
//                                                                           **
// Filename: Swordfish.WPF.Charts\CopyToClipboard.xaml.cs                    **
// Authored by: John Stewien of Swordfish Computing                          **
// Date: April 2006                                                          **
//                                                                           **
// - Change Log -                                                            **
//*****************************************************************************

namespace Swordfish.WPF.Charts
{
    using System;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Input;

    /// <summary>
    /// Interaction logic for UIElementToClipboard.xaml
    /// </summary>
    public partial class CopyToClipboard : UserControl
    {
        #region Delegates

        public delegate void CopyToClipboardDelegateType(FrameworkElement target, double width, double height);

        #endregion

        public static readonly DependencyProperty CopyTargetProperty =
            DependencyProperty.Register("CopyTarget", typeof (FrameworkElement), typeof (CopyToClipboard),
                                        new UIPropertyMetadata(null));

        public CopyToClipboardDelegateType CopyToClipboardDelegate;

        public CopyToClipboard()
        {
            InitializeComponent();
            copyOptions.Visibility = Visibility.Collapsed;
            MouseEnter += UIElementToClipboard_MouseEnter;
            MouseLeave += UIElementToClipboard_MouseLeave;
            CopyToClipboardDelegate = ChartUtilities.CopyFrameworkElementToClipboard;
        }

        // Using a DependencyProperty as the backing store for Text.  This enables animation, styling, binding, etc...

        public FrameworkElement CopyTarget
        {
            get { return (FrameworkElement) GetValue(CopyTargetProperty); }
            set { SetValue(CopyTargetProperty, value); }
        }

        private void UIElementToClipboard_MouseLeave(object sender, MouseEventArgs e)
        {
            copyOptions.Visibility = Visibility.Collapsed;
            Margin = new Thickness(0, 0, 0, 0);
        }

        private void UIElementToClipboard_MouseEnter(object sender, MouseEventArgs e)
        {
            copyOptions.Visibility = Visibility.Visible;
            Margin = new Thickness(0, 0, 0, 8);
        }

        private void bCopy640x480_Click(object sender, RoutedEventArgs e)
        {
            CopyToClipboardDelegate(CopyTarget, 640, 480);
        }

        private void bCopy800x600_Click(object sender, RoutedEventArgs e)
        {
            CopyToClipboardDelegate(CopyTarget, 800, 600);
        }

        private void bCopy1024x768_Click(object sender, RoutedEventArgs e)
        {
            CopyToClipboardDelegate(CopyTarget, 1024, 768);
        }

        private void bCopy1280x1024_Click(object sender, RoutedEventArgs e)
        {
            CopyToClipboardDelegate(CopyTarget, 1280, 1024);
        }

        private void bCopyCustom_Click(object sender, RoutedEventArgs e)
        {
            double width = 640;
            double height = 480;
            Double.TryParse(tbWidth.Text, out width);
            Double.TryParse(tbHeight.Text, out height);
            CopyToClipboardDelegate(CopyTarget, width, height);
        }
    }
}